package com.itdaan.portal.business.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import com.itdaan.portal.business.domain.User;
import com.itdaan.portal.business.service.UserService;
import com.itdaan.portal.common.exception.ViewException;

/**
 * portal上的会员信息业务控制类
 * @author www.itdaan.com
 */
@Controller
@RequestMapping(value = "/member")
@SessionAttributes
public class MemberController {
	
	private Logger logger = LoggerFactory.getLogger(MemberController.class);
	
	@Autowired
	private UserService userService;
	
	@RequestMapping(value = "/{id:\\d+}.html", method = RequestMethod.GET)
    public
    ModelAndView show(
            HttpServletRequest request,
            HttpServletResponse response,
            @PathVariable Integer id            
    ) throws ViewException {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("member/index");
    	try{
    		User user = userService.getById(id);
    		modelAndView.addObject("user", user);
    	}catch(Exception e){
    		e.printStackTrace();
			logger.error("后台业务逻辑出现异常", e);
    	}
    	return modelAndView;
	}	
}
